import os 
import numpy as np 
import pandas as pd 
import glob 
from pathlib import Path
import re

def rename(file_path, memo):
    root = str(Path(file_path).parent)
    name = Path(file_path).name

    l = list(name)
    for i in range(len(l)):
        if l[i] in memo:
            l[i] = memo[l[i]]
    
    new_name = ''.join(l)
    os.rename(os.path.join(root, name), os.path.join(root, new_name))


ps = [r'/data2/autorepair/ruanzhifeng/autorepair_t7_10/t9_DFO/T9_DFO/270FHD/feature_classification_data',
      r'/data2/autorepair/ruanzhifeng/autorepair_t7_10/t9_DFO/T9_DFO/270FHD/original_classification_data']

all_files = []
for p in ps:
    all_files.extend(glob.glob(os.path.join(p, "**/**.jpg"), recursive=True))
    all_files.extend(glob.glob(os.path.join(p, "**/**.json"), recursive=True))

df = pd.DataFrame(data={"file_path": all_files})


all_chinese = []

for img_path in all_files:
    all_chinese.extend(re.findall(r'[\u4e00-\u9fa5]', img_path))

all_chinese_set = list(set(all_chinese))
print(all_chinese_set)

char_letters = list(map(chr, range(65, 91))) + list(map(chr, range(97, 122))) + list('0123456789')

memo = dict(zip(all_chinese_set,  char_letters[:len(all_chinese_set)]))
print(memo)

df['file_path'].apply(lambda x: rename(x, memo))
